package com.demo.blog.controller;


import com.demo.blog.pojo.response.UserInfoParam;
import com.demo.blog.pojo.response.UserInfoResponse;
import com.demo.blog.pojo.response.UserLoginResponse;
import com.demo.blog.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserInfoParam userInfoParam) {
        return userService.login(userInfoParam);
    }
// 获取用户信息
    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId) {
        log.info("获取用户信息, userId:{}", userId);
        return userService.getUserInfo(userId);
    }

    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId) {
        log.info("获取作者信息, userId:{}", blogId);
        return userService.getAuthorInfo(blogId);
    }
}
